from selenium import webdriver
import time

driver= webdriver.Chrome('C:\\Users\Administrator\AppData\Local\Google\Chrome\Application\chromedriver.exe')
driver.get("https://subject.autohome.com.cn/carservice/2019/4/qichedala43/")

links = []

list = driver.find_elements_by_xpath("//ul[@class='w']/li/a")
for l in list:          #循环list中的每一项
#  print(l.get_attribute('href'))  #打印 取出href的值
   links.append(l.get_attribute('href'))

for link in links:
    driver.get("https://account.autohome.com.cn/login?backurl=https%3A%2F%2Fjia.autohome.com.cn%2Fitem%2F107868")
    data = [{'domain': 'jia.autohome.com.cn', 'httpOnly': True, 'name': 'JSESSIONID', 'path': '/', 'secure': False,
             'value': '1BF051B5DFAA4C3BFBFB0F3F4B755C0D'},
            {'domain': '.autohome.com.cn', 'expiry': 1870937509, 'httpOnly': False, 'name': 'fvlid', 'path': '/',
             'secure': False, 'value': '1555577509038ZBGDX4cSPv'},
            {'domain': '.autohome.com.cn', 'expiry': 1558169509.147309, 'httpOnly': False, 'name': 'ahpau', 'path': '/',
             'secure': False, 'value': '1'},
            {'domain': '.autohome.com.cn', 'expiry': 1870937528, 'httpOnly': False, 'name': '__ah_uuid_ng', 'path': '/',
             'secure': False, 'value': 'u_59627888'},
            {'domain': '.autohome.com.cn', 'expiry': 1870937509.147179, 'httpOnly': False, 'name': 'sessionip',
             'path': '/', 'secure': False, 'value': '222.128.11.194'},
            {'domain': '.autohome.com.cn', 'expiry': 1555579328.685536, 'httpOnly': False, 'name': 'sessionvid',
             'path': '/', 'secure': False, 'value': '4774BDE2-5FC9-4DE4-9A4B-17F2AF338516'},
            {'domain': '.autohome.com.cn', 'expiry': 1866617509.14721, 'httpOnly': False, 'name': 'sessionid',
             'path': '/', 'secure': False,
             'value': 'FA2970E2-A321-4FCD-8B1D-591695FEFB42%7C%7C2019-04-18+16%3A51%3A49.101%7C%7C0'},
            {'domain': '.autohome.com.cn', 'expiry': 1866617528.685457, 'httpOnly': False, 'name': 'autoid',
             'path': '/', 'secure': False, 'value': '3f0ef97b7fa2f5fe0b4c905a32c2ef69'},
            {'domain': '.autohome.com.cn', 'expiry': 1618649509, 'httpOnly': False, 'name': '__utma', 'path': '/',
             'secure': False, 'value': '1.562392772.1555577509.1555577509.1555577509.1'},
            {'domain': '.autohome.com.cn', 'expiry': 1870937528.68556, 'httpOnly': False, 'name': 'area', 'path': '/',
             'secure': False, 'value': '110108'},
            {'domain': '.autohome.com.cn', 'expiry': 1555579309, 'httpOnly': False, 'name': '__utmb', 'path': '/',
             'secure': False, 'value': '1.0.10.1555577509'},
            {'domain': '.autohome.com.cn', 'httpOnly': False, 'name': '__utmc', 'path': '/', 'secure': False,
             'value': '1'},
            {'domain': '.autohome.com.cn', 'expiry': 1571345509, 'httpOnly': False, 'name': '__utmz', 'path': '/',
             'secure': False, 'value': '1.1555577509.1.1.utmcsr=(direct)|utmccn=(direct)|utmcmd=(none)'},
            {'domain': '.autohome.com.cn', 'expiry': 3355577528.796756, 'httpOnly': True, 'name': 'pcpopclub',
             'path': '/', 'secure': False, 'value': '587f85fc916640c9966fbd7103aed76c038dd970'},
            {'domain': '.autohome.com.cn', 'expiry': 1617785509, 'httpOnly': False, 'name': 'sessionuid', 'path': '/',
             'secure': False, 'value': 'FA2970E2-A321-4FCD-8B1D-591695FEFB42%7C%7C2019-04-18+16%3A51%3A49.101%7C%7C0'},
            {'domain': '.autohome.com.cn', 'expiry': 3355577528.796788, 'httpOnly': False, 'name': 'clubUserShow',
             'path': '/', 'secure': False, 'value': '59627888|3518|2|ao5s3xcfn|0|0|0||2019-04-18 16:52:08|0'},
            {'domain': '.autohome.com.cn', 'expiry': 1587113527.877119, 'httpOnly': False, 'name': 'autouserid',
             'path': '/', 'secure': False, 'value': '59627888'},
            {'domain': '.autohome.com.cn', 'expiry': 1555663927.87714, 'httpOnly': False, 'name': 'sessionuserid',
             'path': '/', 'secure': False, 'value': '59627888'},
            {'domain': '.autohome.com.cn', 'expiry': 1555663927.877162, 'httpOnly': True, 'name': 'sessionlogin',
             'path': '/', 'secure': False, 'value': 'c7ab6f72faaf440086e17c15721c4612038dd970'},
            {'domain': '.autohome.com.cn', 'expiry': 1555663928, 'httpOnly': False, 'name': 'ahpvno', 'path': '/',
             'secure': False, 'value': '2'},
            {'domain': '.autohome.com.cn', 'expiry': 1571129528.685504, 'httpOnly': False, 'name': 'ref', 'path': '/',
             'secure': False, 'value': '0%7C0%7C0%7C0%7C2019-04-18+16%3A52%3A08.639%7C2019-04-18+16%3A51%3A49.101'}]
    for d in data:
        driver.add_cookie(d)
    driver.get(link)
    time.sleep(5)

